/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tnviet.proj.jna.utilities;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author Administrator
 */
public class PcapFileFilter extends FileFilter{
    String description;
    String[] extensions;

    public PcapFileFilter(String description, String[] extensions) {
        if(description == null){
            this.description = this.extensions[0] + "{" + extensions.length + "}";
        } else {
            this.description = description;
        }
        this.extensions = (String[])extensions.clone();
    }

    public PcapFileFilter(String description, String extensions){
        this(description, new String[]{extensions});
    }
    public String getDescription(){
        return description;
    }


    @Override
    public boolean accept(File f) {
        if(f.isDirectory()){
            return true;
        } else {
            String path = f.getAbsolutePath().toLowerCase();
            for(int i = 0; i < extensions.length; i++){
                String extension = extensions[i];
                if((path.endsWith(extension))&& (path.charAt(path.length() - extension.length() - 1)=='.')){
                    return true;
                }
            }
        }
        return false;
    }

 

}
